<template>
	<view>
		<!-- 页面内容开始 -->
		<!-- 表格搜索组件开始 -->
		<vk-data-table-query
			v-model="queryForm1.formData"
			:columns="queryForm1.columns"
			:main-columns="['no','title','type','add_type']"
			size="mini"
			@search="search"
		></vk-data-table-query>
		<!-- 表格搜索组件结束 -->

		<!-- 表格组件开始 -->
		<vk-data-table
			ref="table1"
			:action="table1.action"
			:columns="table1.columns"
			:query-form-param="queryForm1"
			:right-btns="['detail_auto']"
			:selection="false"
			:row-no="true"
			:pagination="true"
			size="mini"
			@update="updateBtn"
			@delete="deleteBtn"
			@current-change="currentChange"
			@selection-change="selectionChange"
		></vk-data-table>
		<!-- 表格组件结束 -->

		<!-- 页面内容结束 -->
	</view>
</template>

<script>
var that; // 当前页面对象
var vk = uni.vk;									// vk实例
var addTypeData = vk.getVuex('$app.config.maill.rec.addType');
export default {
	props: {
		user:{
			Type:Object,
		}
	},
	data: function() {
		// 组件创建时,进行数据初始化
		return {
			// 页面是否请求中或加载中
			loading: false,
			// init请求返回的数据
			data: {},
			// 表格相关开始 -----------------------------------------------------------
			table1: {
				// 表格数据请求地址
				action: "admin/business/sys/user.getBalanceRecords",
				// 表格字段显示规则
				columns: [
					{ key: "value", title: "本次变动", type: "html", width: 120, defaultValue: "暂无", align:"right",
						formatter: (val, row, column, index) => {
							let valStr = vk.pubfn.priceFilter(val);
							let str = val > 0 ? `<text>+${valStr}</text>` : `<text style="color:#f56c6c">${valStr}</text>`;
							return str;
						}
					},
					{ key: "balance", title: "当时余额", type: "money", width: 120, defaultValue: "暂无" },
					{ key: "title", title: "标题", type: "text", width: 150, defaultValue: "暂无", align:"left" },
					{ key: "comment", title: "备注", type: "text", width: 150, defaultValue: "暂无", align:"left" },
					{ key: "type",title: "收入/支出",type: "tag",width: 120,defaultValue: "暂无",
						data:[
							{ value:1, label:"收入", tagType:"success" },
							{ value:2, label:"支出", tagType:"danger" }
						]
					},
					{ key: "add_type",title: "添加方式",type: "select",width: 140, data: addTypeData },
					{ key: "no", title: "单号", type: "text", width: 220, defaultValue: "暂无" },
					{ key: "_add_time", title: "本条记录时间", type: "time", width: 180 },
					{ key: "_id", title: "id", type: "text", width: 280 }
				],
				// 多选框选中的值
				multipleSelection: [],
				// 当前高亮的记录
				selectItem: ""
			},
			// 表格相关结束 -----------------------------------------------------------
			// 表单相关开始 -----------------------------------------------------------
			// 查询表单请求数据
			queryForm1: {
				// 查询表单数据源，可在此设置默认值
				formData: {

				},
				// 查询表单的字段规则 fieldName:指定数据库字段名,不填默认等于key
				columns: [
					{ key: "_add_time", title: "添加时间", type: "datetimerange", width: 400, mode: "[]" },
					{ key: "min_value",title: "金额范围",type: "money",width: 150,placeholder: "请输入最小金额",
						fieldName: "value",mode: ">=" ,
					},
					{ key: "max_value",title: "-",type: "money",width: 150,placeholder: "请输入最大金额",
						fieldName: "value",mode: "<=",
					},
					{ key: "no", title: "订单号", type: "text", width: 150, placeholder: "请输入订单号" },
					{ key: "title", title: "标题", type: "text", width: 150, mode: "%%" },
					{ key: "type",title: "类型",type: "select",width: 150,placeholder: "请选择交易类型",
						data: [
							{ value: 1, label: "收入" },
							{ value: 2, label: "支出" },
						],
					},
					{ key: "add_type", title: "添加方式", type: "select", width: 150, mode: "=", data: addTypeData },
					{ key: "comment", title: "备注", type: "text", width: 150, mode: "%%" },
					{ key: "user_id", title: "用户id", type: "text", width: 150, mode: "=", show:["none"] }
				]
			}
			// 表单相关结束-----------------------------------------------------------
		};
	},
	created() {
		that = this;
		that.init();
	},
	mounted() {},
	methods: {
		// 初始化
		init() {
			that.queryForm1.formData.user_id = that.user._id;
		},
		// 页面打开
		pageOpen() {
			that = this;
			let { value, form1 } = that;
			let { item } = value;
		},
		// 页面关闭
		pageClose() {},
		// 页面返回
		pageBack() {
			let { value } = that;
			value.show = false;
			that.$emit("input", value);
		},
		// 搜索
		search() {
			that.$refs.table1.query();
			that.$emit("refresh");
		},
		// 刷新
		refresh() {
			that.$refs.table1.refresh();
			that.$emit("refresh");
		},
		// 获取当前选中的行的数据
		getCurrentRow() {
			return that.$refs.table1.getCurrentRow();
		},
		// 监听 - 行的选中高亮事件
		currentChange(val) {
			that.selectItem = val;
			that.showOneBtn = val ? true : false;
		},
		// 当选择项发生变化时会触发该事件
		selectionChange(list) {
			that.multipleSelection = list;
		}
	},
	// 监听属性
	watch: {},
	// 计算属性
	computed: {}
};
</script>

<style lang="scss" scoped></style>
